package net.lab1024.sa.user.module.business.points.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.lab1024.sa.common.common.domain.PageResult;
import net.lab1024.sa.common.common.domain.ResponseDTO;
import net.lab1024.sa.common.common.util.SmartRequestUtil;
import net.lab1024.sa.user.constant.UserSwaggerTagConst;
import net.lab1024.sa.user.module.business.points.domain.form.ApplyPointsForm;
import net.lab1024.sa.user.module.business.points.domain.form.PointsChangeRecordQueryForm;
import net.lab1024.sa.user.module.business.points.domain.vo.PointsBalanceVO;
import net.lab1024.sa.user.module.business.points.domain.vo.PointsChangeRecordVO;
import net.lab1024.sa.user.module.business.points.service.PointsChangeRecordService;
import net.lab1024.sa.user.module.business.points.service.PointsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 积分 Controller
 *
 * @Author jabari
 * @Date 2023-07-12 14:28:55
 * @Copyright 51dev
 */

@RestController
@Api(tags = UserSwaggerTagConst.Business.POINTS)
public class PointsController {

    @Autowired
    private PointsChangeRecordService pointsChangeRecordService;
    @Autowired
    private PointsService pointsService;

    @ApiOperation("申请积分 @author jabari")
    @PostMapping("/points/applyPoints")
    public ResponseDTO<String> applyPoints(@RequestBody @Valid ApplyPointsForm applyPointsForm){

        return pointsService.applyPoints(applyPointsForm);
    }

    @ApiOperation("获取积分余额 @author jabari")
    @PostMapping("/points/getPointsBalance")
    public ResponseDTO<PointsBalanceVO> getPointsBalance(){

        return pointsService.getPointsBalance();
    }


    @ApiOperation("获取积分变更记录 @author jabari")
    @PostMapping("/points/getPointsChangeRecordList")
    public ResponseDTO<PageResult<PointsChangeRecordVO>> queryPage(@RequestBody @Valid PointsChangeRecordQueryForm queryForm) {
        queryForm.setUserId(SmartRequestUtil.getRequestUserId());
        return ResponseDTO.ok(pointsChangeRecordService.queryPage(queryForm));
    }


}
